package cn.xscrum.vtsp.controller;

import java.util.List;


import cn.xscrum.vtsp.vo.VtspActivityVo;
import cn.xscrum.demo.domain.UserOperateModel;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.xscrum.common.annotation.Log;
import cn.xscrum.common.enums.BusinessType;
import cn.xscrum.vtsp.domain.VtspActivity;
import cn.xscrum.vtsp.service.IVtspActivityService;
import cn.xscrum.common.core.controller.BaseController;
import cn.xscrum.common.core.domain.AjaxResult;
import cn.xscrum.common.utils.poi.ExcelUtil;
import cn.xscrum.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 活动信息Controller
 * 
 * @author xscrum
 * @date 2021-10-01
 */
@Controller
@RequestMapping("/vtsp/activity")
public class VtspActivityController extends BaseController
{
    private String prefix = "vtsp/activity";

    @Autowired
    private IVtspActivityService vtspActivityService;

    @RequiresPermissions("vtsp:activity:view")
    @GetMapping()
    public String activity()
    {
        return prefix + "/activity";
    }

    /**
	 * 查询活动信息列表
     */
    @RequiresPermissions("vtsp:activity:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(VtspActivity vtspActivity)
    {
        startPage();
        List<VtspActivity> list = vtspActivityService.selectVtspActivityList(vtspActivity);
        return getDataTable(list);
    }

    /**
	 * 导出活动信息列表
     */
    @RequiresPermissions("vtsp:activity:export")
    @Log(title = "活动信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(VtspActivity vtspActivity)
    {
        List<VtspActivity> list = vtspActivityService.selectVtspActivityList(vtspActivity);
        ExcelUtil<VtspActivity> util = new ExcelUtil<VtspActivity>(VtspActivity.class);
        return util.exportExcel(list, "activity");
    }

    /**
	 * 新增活动信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
	 * 新增保存活动信息
     */
    @RequiresPermissions("vtsp:activity:add")
    @Log(title = "活动信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(VtspActivity vtspActivity)
    {
        return toAjax(vtspActivityService.insertVtspActivity(vtspActivity));
    }

    /**
	 * 修改活动信息
     */
    @GetMapping("/edit/{activityId}")
    public String edit(@PathVariable("activityId") Long activityId, ModelMap mmap)
    {
        VtspActivity vtspActivity = vtspActivityService.selectVtspActivityById(activityId);
        mmap.put("vtspActivity", vtspActivity);
        return prefix + "/edit";
    }

    /**
	 * 修改保存活动信息
     */
    @RequiresPermissions("vtsp:activity:edit")
    @Log(title = "活动信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(VtspActivity vtspActivity)
    {
        return toAjax(vtspActivityService.updateVtspActivity(vtspActivity));
    }

    /**
	 * 删除活动信息
     */
    @RequiresPermissions("vtsp:activity:remove")
    @Log(title = "活动信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(vtspActivityService.deleteVtspActivityByIds(ids));
    }
}
